package com.lagou.consumer;

import com.lagou.common.pojo.Order;
import com.lagou.common.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@RocketMQMessageListener(topic = "payment-delay-mq",consumerGroup = "springboot-mq-consumer-2")
public class OverdueConsumer implements RocketMQListener<Order> {

    @Autowired
    private OrderService orderService;

    /**
     * 订单支付过期，取消订单
     * @param order
     */
    @Override
    public void onMessage(Order order) {
        System.out.print("-------- 延时支付： ");
        System.out.println(order);

        orderService.overdueAndCancel(order.getId());
    }
}
